package com.ljz.servlet;

import com.ljz.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;


@WebServlet("/getvalue")
public class GetSessionValueServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, IOException {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        String name;
        if (user == null) {
            name = "";
        } else {
            name = user.getUname();
        }
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write("{\"name\": \"" + name + "\"}");
    }
}
